import javax.sound.midi.Soundbank;
import java.io.FileOutputStream;
import java.util.Scanner;

/**
 * @author BianWenKai
 * @DATE 2021/8/20 - 23:17
 **/
public class Variable {

    //类变量
    static String id;
    //常量,修饰符不区分前后顺序（public、static、final……)
    static final double PI = 3.14D;
    //实例变量
    String name;
    public static void main(String[] args) {
        //局部变量
        int i = 0;
        final double Pi = 3.1415926d;
        System.out.println(i);
        Variable variable = new Variable();
        System.out.println(variable.name);
        System.out.println(id);
        System.out.println(Pi);
        System.out.println(max(3, 2));

        String s1 = new String("hello");
        String s2 = new String("hello");

        String s3 = "hello";
        String s4 = "hello";

        System.out.println(s1 == s2);//false
        System.out.println(s3 == s4);//true
    }

    public static void var(){
        //自动类型转换，低 ——> 高
        int a = 1;
        double b = 2;
        System.out.println(a+b);
        System.out.println((int)(a+b));
    }

    public static void averageNum(){
        int i = 0 ,sum = 0;
        int count = 0;
        System.out.println("please input int number");
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()){
            i = scanner.nextInt();
            sum += i;
            count ++;
        }
        scanner.close();
        System.out.println("输入非数字，程序结束");

        System.out.println("和："+sum + "平均数："+(float)sum/count);
    }

    public static void sum(){
        int evenNumberSum = 0;
        int oddNumberSum = 0;
        for (int i = 0; i < 100; i++) {
            if (i%2 == 0)
                evenNumberSum += i;  //偶数
            else
                oddNumberSum += i;  //奇数
        }
        System.out.println(evenNumberSum);
        System.out.println(oddNumberSum);

        int i = 0;
        while (i <= 1000){
            if (i % 5 == 0)
                System.out.print(i+"\t");
            i++;
            if (i%15 == 0)
                System.out.println();
        }
    }

    public static void multipleTable(){
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(j+"*"+i+"="+i*j+"\t");
            }
            System.out.println();
        }
    }

    // 求质数：除过1和其本身再没有其它因数的自然数，1不是质数
    // 所有的自然数都能被1整除，所以只需要判断要求的数除1和自身之外还有没有其它因数，有则不是质数，否则就是质数
    public static void primeNumber(){
        // i / j == 0 ； 判断 i==j 否则说明有其他因数存在，则不是质数
        for (int i = 1; i <= 100 ; ++i) {
            for (int j = 2 ; j <= i; j++) {
                if (i % j == 0 && i != j) {
                    break;
                }
                if (i == j)
                    System.out.println(i);
            }
        }
    }

    public static void printTriangle(){
        for (int i = 0; i < 5; i++) {
            for (int j = 5; j >= i; j--) {
                System.out.print(" ");
            }
            for (int j = 0; j <= i; j++) {
                System.out.print("*");
            }
            for (int j = 0; j < i; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

    public static int max(int a, int b){
        return a>b?a:b;
    }
}
